﻿@{
    ViewBag.Title = "供货商档案";
    Layout = "~/Views/Shared/_ListLayout.cshtml";
}
@section toolbar{
    <table style="width: 100%;">
        <tr>
            <td style="width: 100%;">
                <a class="mini-button" iconcls="icon-add" onclick="editRow('')" plain="true">增加</a>
                @*<a class="mini-button" iconcls="icon-remove" onclick="remove()" plain="true">删除</a>*@
                <a class="mini-button" iconcls="icon-date-magnify" onclick="showSearchWindow()" plain="true">
                    筛选</a> <span class="separator"></span>
            </td>
            <td style="white-space: nowrap;">
                <input id="ifexame" class="mini-combobox" textField="text" valueField="id" value="" url="/Category/ExameItems" nullItemText="--是否审核--" emptyText="--是否审核--" onvaluechanged="search()" />  
                <input id="SupName" class="mini-textbox" emptytext="请输入名称" style="width: 150px;"
                    onenter="onKeyEnter" />
                <a class="mini-button" onclick="search()">查询</a>
            </td>
        </tr>
    </table>
}
@section script
{
    <script type="text/javascript">
        mini.parse();
        function showSearchWindow() {
            var win = mini.get("searchWindow");
            win.show();
        }
        function advSearch() {
            var frm = new mini.Form("frmAdv");
            grid.load(frm.getData(true));
            var win = mini.get("searchWindow");
            win.hide();
        }
        function search() {
            grid.load({
                "key": mini.get("#SupName").value,
                "IfExamine": mini.get("#ifexame").value
            });
        }
        function editRow(id) {
            mini.open({
                url: "/Archives/SupplierEdit/" + id,
                title: "供应商管理",
                iconCls: "icon-user",
                allowResize: false,
                width: 680,
                height: 510,
                onload: function () {
                    //var iframe = this.getIFrameEl();
                    //var data = { action: "new" };
                    //iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {

                    grid.reload();
                }
            });
        }
//        function deleteItem(id) {
//            $.ajax({
//                url: "/Archives/SupplierDelete",
//                data: { ids: id },
//                success: function (text) {
//                    grid.reload();
//                },
//                error: function () {
//                }
//            });
//        }
        function deleteItem(id) {
            $.ajax({
                url: "/Archives/SupplierDelete",
                data: { ids: id },
                dataType: "json",
                success: function (j) {
                    if (j == false) {
                        if (confirm("将要删除的供货商存在采购数据，删除后将影响整个系统运行，是否确认删除？") == true) {
                            $.ajax({
                                url: "/Archives/SupplierDelete",
                                data: { ids: id, confirm: "true" },
                                dataType: "json",
                                success: function (r) {
                                    grid.reload();
                                }
                            });
                        }
                    }

                },
                error: function () {
                }
            });
        }
        function exame(obj, itemid, old) {
            $.ajax({
                url: "/Archives/SupplierExame/" + itemid,
                success: function (j) {
                    if (j == true) {
                        $(obj).css("color", "green").text("是");
                    }
                    else {
                        $(obj).css("color", "red").text("否");
                    }
                    $(obj).removeProp("onclick");
                    $(obj).unbind("click").click(function () {
                        exame(obj, itemid, !old)
                    })
                },
                error: function () {
                    alert("失败")
                }
            });
        }
        
        function onNormalActionRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record.Id;
            var rowIndex = e.rowIndex;
//            if (record.IfExamine) {
//                if (record.IfExamine == "true") {
//                    return "";
//                }
//            }

            var s = ' <a class="Edit_Button" href="javascript:editRow(\'' + uid + '\')" >编辑</a>'
                + ' <a class="Delete_Button" href="javascript:if(confirm(\'确定要删除这条记录吗？\')){deleteItem(\'' + uid + '\')}">删除</a>';
            return s;
        }
    </script>
}
<div id="datagrid1" class="mini-datagrid" url="/Archives/SearchSupplierArchiveList"
    style="width: 100%; height: 100%;" idfield="id" allowresize="false" sizelist="[20,30,50,100]"
    pagesize="20" multiselect="true">
    <div property="columns">
        <div type="indexcolumn" width="30">
        </div>
        <div type="checkcolumn" width="30">
        </div>
        <div field="LoginName" headeralign="center" align="center" width="60">
            登录名</div>
        <div field="SupName" headeralign="center" align="center" width="160">
            名称</div>
        <div field="PyCode" headeralign="center" align="center" width="80">
            拼音码</div>
        <div field="SupTypeName" headeralign="center" align="center" width="60">
            供货商类型</div>
        <div field="Functionary" headeralign="center" align="center" width="60">
            负责人</div>
        <div field="FunctionaryPhone" headeralign="center" align="center" width="60">
            负责人电话</div>
        <div field="Linkman" headeralign="center" align="center" width="60">
            联系人</div>
        <div field="ContactPhone" headeralign="center" align="center" width="60">
            联系人电话</div>
        <div field="OfficePhone" headeralign="center" align="center" width="60">
            办公电话</div>
        <div field="FaxPhone" headeralign="center" align="center" width="60">
            传真</div>
        <div field="eMail" headeralign="center" align="center" width="60">
            邮箱</div>
        <div field="IfExamine" headeralign="center" align="center" width="40" renderer="onExamRender">
            审核</div>
        <div name="action" width="120" headeralign="center" align="center" renderer="onNormalActionRenderer"
            cellstyle="padding:0;">
            管理</div>
    </div>
</div>
<div id="searchWindow" class="mini-window" title="高级筛选" style="width: 450px; height: 250px;"
    iconcls="icon-date-magnify" showmaxbutton="true" showtoolbar="true" showfooter="true"
    showmodal="false" allowresize="false" allowdrag="true">
    <div property="footer" style="text-align: right; padding: 5px; padding-right: 15px;">
        <a class="mini-button" iconcls="icon-zoom" onclick="advSearch()" style='vertical-align: middle;'>
            筛选</a>
    </div>
    <form id="frmAdv">
    <table class="edittable" border="1" cellpadding="0" cellspacing="0">
	<tr>
		<td style="width:60px;">
            名称:
        </td>
        <td colspan="2">
            <input name="SupName" class="mini-textbox" required="true" width="192"/>
        </td>
        <td style="width:150px;">
            
        </td>
	</tr>
	<tr>
		<td>
            拼音码:
        </td>
        <td>
            <input name="PyCode" class="mini-textbox" required="true"/>
        </td>
		<td>
            类型:
        </td>
        <td>
            <input name="SupTypeCode" class="mini-combobox"  textField="text" valueField="id" emptyText="请选择..." url="/Category/PaSupTypes" allowInput="false" showNullItem="true" nullItemText="请选择..."/> 
        </td>
	</tr>
	<tr>
		<td>
            负责人:
        </td>
        <td>
            <input name="Functionary"  class="mini-textbox" />
        </td>
		<td>
            负责人电话:
        </td>
        <td>
            <input name="FunctionaryPhone" class="mini-textbox"/>
        </td>
	</tr>
	<tr>
		<td>
            联系人:
        </td>
        <td>
            <input name="Linkman" class="mini-textbox" />
        </td>
		<td>
            联系人电话:
        </td>
        <td>
            <input name="ContactPhone" class="mini-textbox" />
        </td>
	</tr>
	<tr>
		<td>
            联系地址:
        </td>
        <td>
            <input name="ContactAddress" class="mini-textbox" />
        </td>
		<td>
            办公电话:
        </td>
        <td>
            <input name="OfficePhone" class="mini-textbox" />
        </td>
	</tr>
	<tr>
		<td>
            传真:
        </td>
        <td>
            <input name="FaxPhone" class="mini-textbox" />
        </td>
		<td>
            邮箱:
        </td>
        <td>
            <input name="eMail" class="mini-textbox" />
        </td>
	</tr>

</table>
    </form>
</div>
